home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / xfonts-utils.postinst < prev    next >
Encoding:
Text File  |  2009-12-25  |  20.6 KB  |  644 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. THIS_PACKAGE=xfonts-utils
  6. THIS_SCRIPT=postinst
  7.  
  8. # This is the X Strike Force shell library for X Window System package
  9. # maintainer scripts.  It serves to define shell functions commonly used by
  10. # such packages, and performs some error checking necessary for proper operation
  11. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  12. # invoke the functions defined here to accomplish package installation and
  13. # removal tasks.
  14.  
  15. # If you are reading this within a Debian package maintainer script (e.g.,
  16. # /var/lib/dpkg/info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  17. # skip past this library by scanning forward in this file to the string
  18. # "GOBSTOPPER".
  19.  
  20. SOURCE_VERSION=1:7.5+2
  21. OFFICIAL_BUILD=
  22.  
  23. # Use special abnormal exit codes so that problems with this library are more
  24. # easily tracked down.
  25. SHELL_LIB_INTERNAL_ERROR=86
  26. SHELL_LIB_THROWN_ERROR=74
  27. SHELL_LIB_USAGE_ERROR=99
  28.  
  29. # old -> new variable names
  30. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  31.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  32. fi
  33. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  34.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  35. fi
  36.  
  37. # initial sanity checks
  38. if [ -z "$THIS_PACKAGE" ]; then
  39.   cat >&2 <<EOF
  40. Error: package maintainer script attempted to use shell library without
  41. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  42. version, and the text of this error message to the Debian Bug Tracking System.
  43. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  44. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  45. "doc-debian" package, or install the "reportbug" package and use the command of
  46. the same name to file a report against version $SOURCE_VERSION of this package.
  47. EOF
  48.   exit $SHELL_LIB_USAGE_ERROR
  49. fi
  50.  
  51. if [ -z "$THIS_SCRIPT" ]; then
  52.   cat >&2 <<EOF
  53. Error: package maintainer script attempted to use shell library without
  54. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  55. version, and the text of this error message to the Debian Bug Tracking System.
  56. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  57. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  58. "doc-debian" package, or install the "reportbug" package and use the command of
  59. the same name to file a report against version $SOURCE_VERSION of the
  60. "$THIS_PACKAGE" package.
  61. EOF
  62.   exit $SHELL_LIB_USAGE_ERROR
  63. fi
  64.  
  65. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  66.   RECONFIGURE="true"
  67. else
  68.   RECONFIGURE=
  69. fi
  70.  
  71. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  72.   FIRSTINST="yes"
  73. fi
  74.  
  75. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  76.   UPGRADE="yes"
  77. fi
  78.  
  79. trap "message;\
  80.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  81.       message;\
  82.       exit 1" HUP INT QUIT TERM
  83.  
  84. reject_nondigits () {
  85.   # syntax: reject_nondigits [ operand ... ]
  86.   #
  87.   # scan operands (typically shell variables whose values cannot be trusted) for
  88.   # characters other than decimal digits and barf if any are found
  89.   while [ -n "$1" ]; do
  90.     # does the operand contain anything but digits?
  91.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  92.       # can't use die(), because it wraps message() which wraps this function
  93.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  94.            "possibly malicious garbage \"$1\"" >&2
  95.       exit $SHELL_LIB_THROWN_ERROR
  96.     fi
  97.     shift
  98.   done
  99. }
  100.  
  101. reject_unlikely_path_chars () {
  102.   # syntax: reject_unlikely_path_chars [ operand ... ]
  103.   #
  104.   # scan operands (typically shell variables whose values cannot be trusted) for
  105.   # characters unlikely to be seen in a path and which the shell might
  106.   # interpret and barf if any are found
  107.   while [ -n "$1" ]; do
  108.     # does the operand contain any funny characters?
  109.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  110.       # can't use die(), because I want to avoid forward references
  111.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  112.            "encountered possibly malicious garbage \"$1\"" >&2
  113.       exit $SHELL_LIB_THROWN_ERROR
  114.     fi
  115.     shift
  116.   done
  117. }
  118.  
  119. # Query the terminal to establish a default number of columns to use for
  120. # displaying messages to the user.  This is used only as a fallback in the
  121. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  122. # the script is running, and this cannot, only being calculated once.)
  123. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  124. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  125.   DEFCOLUMNS=80
  126. fi
  127.  
  128. message () {
  129.   # pretty-print messages of arbitrary length
  130.   reject_nondigits "$COLUMNS"
  131.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  132. }
  133.  
  134. observe () {
  135.   # syntax: observe message ...
  136.   #
  137.   # issue observational message suitable for logging someday when support for
  138.   # it exists in dpkg
  139.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  140.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  141.   fi
  142. }
  143.  
  144. warn () {
  145.   # syntax: warn message ...
  146.   #
  147.   # issue warning message suitable for logging someday when support for
  148.   # it exists in dpkg; also send to standard error
  149.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  150. }
  151.  
  152. die () {
  153.   # syntax: die message ...
  154.   #
  155.   # exit script with error message
  156.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  157.   exit $SHELL_LIB_THROWN_ERROR
  158. }
  159.  
  160. internal_error () {
  161.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  162.   message "internal error: $*"
  163.   if [ -n "$OFFICIAL_BUILD" ]; then
  164.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  165.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  166.             "Tracking System.  Include all messages above that mention the" \
  167.             "$THIS_PACKAGE package.  Visit " \
  168.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  169.             "instructions, read the file" \
  170.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  171.             "package, or install the reportbug package and use the command of" \
  172.             "the same name to file a report."
  173.   fi
  174.   exit $SHELL_LIB_INTERNAL_ERROR
  175. }
  176.  
  177. usage_error () {
  178.   message "usage error: $*"
  179.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  180.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  181.           "Tracking System.  Include all messages above that mention the" \
  182.           "$THIS_PACKAGE package.  Visit " \
  183.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  184.           "instructions, read the file" \
  185.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  186.           "package, or install the reportbug package and use the command of" \
  187.           "the same name to file a report."
  188.   exit $SHELL_LIB_USAGE_ERROR
  189. }
  190.  
  191. font_update () {
  192.   # run $UPDATECMDS in $FONTDIRS
  193.  
  194.   local dir cmd shortcmd x_font_dir_prefix
  195.  
  196.   x_font_dir_prefix="/usr/share/fonts/X11"
  197.  
  198.   if [ -z "$UPDATECMDS" ]; then
  199.     usage_error "font_update() called but \$UPDATECMDS not set"
  200.   fi
  201.   if [ -z "$FONTDIRS" ]; then
  202.     usage_error "font_update() called but \$FONTDIRS not set"
  203.   fi
  204.  
  205.   reject_unlikely_path_chars "$UPDATECMDS"
  206.   reject_unlikely_path_chars "$FONTDIRS"
  207.  
  208.   for dir in $FONTDIRS; do
  209.     if [ -d "$x_font_dir_prefix/$dir" ]; then
  210.       for cmd in $UPDATECMDS; do
  211.         if which "$cmd" > /dev/null 2>&1; then
  212.           shortcmd=${cmd##*/}
  213.           observe "running $shortcmd in $dir font directory"
  214.       cmd_opts=
  215.           if [ "$shortcmd" = "update-fonts-alias" ]; then
  216.             cmd_opts=--x11r7-layout
  217.           fi
  218.           if [ "$shortcmd" = "update-fonts-dir" ]; then
  219.             cmd_opts=--x11r7-layout
  220.           fi
  221.           if [ "$shortcmd" = "update-fonts-scale" ]; then
  222.             cmd_opts=--x11r7-layout
  223.           fi
  224.           $cmd $cmd_opts $dir || warn "$cmd $cmd_opts $dir" \
  225.                               "failed; font directory data may not" \
  226.                               "be up to date"
  227.         else
  228.           warn "$cmd not found; not updating corresponding $dir font" \
  229.                "directory data"
  230.         fi
  231.       done
  232.     else
  233.       warn "$dir is not a directory; not updating font directory data"
  234.     fi
  235.   done
  236. }
  237.  
  238. remove_conffile_prepare () {
  239.   # syntax: remove_conffile_prepare filename official_md5sum ...
  240.   #
  241.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  242.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  243.   # operands provided, then prepare the conffile for removal from the system.
  244.   # We defer actual deletion until the package is configured so that we can
  245.   # roll this operation back if package installation fails.
  246.   #
  247.   # Call this function from a preinst script in the event $1 is "upgrade" or
  248.   # "install" and verify $2 to ensure the package is being upgraded from a
  249.   # version (or installed over a version removed-but-not-purged) prior to the
  250.   # one in which the conffile was obsoleted.
  251.  
  252.   local conffile current_checksum
  253.  
  254.   # validate arguments
  255.   if [ $# -lt 2 ]; then
  256.     usage_error "remove_conffile_prepare() called with wrong number of" \
  257.                 "arguments; expected at least 2, got $#"
  258.     exit $SHELL_LIB_USAGE_ERROR
  259.   fi
  260.  
  261.   conffile="$1"
  262.   shift
  263.  
  264.   # does the conffile even exist?
  265.   if [ -e "$conffile" ]; then
  266.     # calculate its checksum
  267.     current_checksum=$(md5sum < "$conffile" | sed 's/[[:space:]].*//')
  268.     # compare it to each supplied checksum
  269.     while [ -n "$1" ]; do
  270.       if [ "$current_checksum" = "$1" ]; then
  271.         # we found a match; move the confffile and stop looking
  272.         observe "preparing obsolete conffile $conffile for removal"
  273.         mv "$conffile" "$conffile.$THIS_PACKAGE-tmp"
  274.         break
  275.       fi
  276.       shift
  277.     done
  278.   fi
  279. }
  280.  
  281. remove_conffile_lookup () {
  282.   # syntax: remove_conffile_lookup package filename
  283.   #
  284.   # Lookup the md5sum of a conffile in dpkg's database, and prepare for removal
  285.   # if it matches the actual file's md5sum.
  286.   #
  287.   # Call this function when you would call remove_conffile_prepare but only
  288.   # want to check against dpkg's status database instead of known checksums.
  289.  
  290.   local package conffile old_md5sum
  291.  
  292.   # validate arguments
  293.   if [ $# -ne 2 ]; then
  294.     usage_error "remove_conffile_lookup() called with wrong number of" \
  295.                 "arguments; expected 1, got $#"
  296.     exit $SHELL_LIB_USAGE_ERROR
  297.   fi
  298.  
  299.   package="$1"
  300.   conffile="$2"
  301.  
  302.   if ! [ -e "$conffile" ]; then
  303.     return
  304.   fi
  305.   old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$package" | \
  306.     awk '{ if (match($0, "^ '"$conffile"' ")) print $2}')"
  307.   if [ -n "$old_md5sum" ]; then
  308.     remove_conffile_prepare "$conffile" "$old_md5sum"
  309.   fi
  310. }
  311.  
  312. remove_conffile_commit () {
  313.   # syntax: remove_conffile_commit filename
  314.   #
  315.   # Complete the removal of a conffile "filename" that has become obsolete.
  316.   #
  317.   # Call this function from a postinst script after having used
  318.   # remove_conffile_prepare() in the preinst.
  319.  
  320.   local conffile
  321.  
  322.   # validate arguments
  323.   if [ $# -ne 1 ]; then
  324.     usage_error "remove_conffile_commit() called with wrong number of" \
  325.                 "arguments; expected 1, got $#"
  326.     exit $SHELL_LIB_USAGE_ERROR
  327.   fi
  328.  
  329.   conffile="$1"
  330.  
  331.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  332.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  333.     observe "committing removal of obsolete conffile $conffile"
  334.     rm "$conffile.$THIS_PACKAGE-tmp"
  335.   fi
  336. }
  337.  
  338. remove_conffile_rollback () {
  339.   # syntax: remove_conffile_rollback filename
  340.   #
  341.   # Roll back the removal of a conffile "filename".
  342.   #
  343.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  344.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  345.   # preinst.
  346.  
  347.   local conffile
  348.  
  349.   # validate arguments
  350.   if [ $# -ne 1 ]; then
  351.     usage_error "remove_conffile_rollback() called with wrong number of" \
  352.                 "arguments; expected 1, got $#"
  353.     exit $SHELL_LIB_USAGE_ERROR
  354.   fi
  355.  
  356.   conffile="$1"
  357.  
  358.   # if the temporary file created by remove_conffile_prepare() exists, move it
  359.   # back
  360.   if [ -e "$conffile.$THIS_PACKAGE-tmp" ]; then
  361.     observe "rolling back removal of obsolete conffile $conffile"
  362.     mv "$conffile.$THIS_PACKAGE-tmp" "$conffile"
  363.   fi
  364. }
  365.  
  366. replace_conffile_with_symlink_prepare () {
  367.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  368.   # official_md5sum ...
  369.   #
  370.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  371.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  372.   # operands provided, then prepare the conffile for removal from the system.
  373.   # We defer actual deletion until the package is configured so that we can
  374.   # roll this operation back if package installation fails. Otherwise copy it
  375.   # to newfilename and let dpkg handle it through conffiles mechanism.
  376.   #
  377.   # Call this function from a preinst script in the event $1 is "upgrade" or
  378.   # "install" and verify $2 to ensure the package is being upgraded from a
  379.   # version (or installed over a version removed-but-not-purged) prior to the
  380.   # one in which the conffile was obsoleted.
  381.  
  382.   local conffile current_checksum
  383.  
  384.   # validate arguments
  385.   if [ $# -lt 3 ]; then
  386.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  387.                 " number of arguments; expected at least 3, got $#"
  388.     exit $SHELL_LIB_USAGE_ERROR
  389.   fi
  390.  
  391.   oldconffile="$1"
  392.   shift
  393.   newconffile="$1"
  394.   shift
  395.  
  396.   remove_conffile_prepare "$_oldconffile" "$@"
  397.   # If $oldconffile still exists, then md5sums didn't match.
  398.   # Copy it to new one.
  399.   if [ -f "$oldconffile" ]; then
  400.     cp "$oldconffile" "$newconffile"
  401.   fi
  402.  
  403. }
  404.  
  405. replace_conffile_with_symlink_commit () {
  406.   # syntax: replace_conffile_with_symlink_commit oldfilename
  407.   #
  408.   # Complete the removal of a conffile "oldfilename" that has been
  409.   # replaced by a symlink.
  410.   #
  411.   # Call this function from a postinst script after having used
  412.   # replace_conffile_with_symlink_prepare() in the preinst.
  413.  
  414.   local conffile
  415.  
  416.   # validate arguments
  417.   if [ $# -ne 1 ]; then
  418.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  419.                 "number of arguments; expected 1, got $#"
  420.     exit $SHELL_LIB_USAGE_ERROR
  421.   fi
  422.  
  423.   conffile="$1"
  424.  
  425.   remove_conffile_commit "$conffile"
  426. }
  427.  
  428. replace_conffile_with_symlink_rollback () {
  429.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  430.   #
  431.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  432.   # "newfilename".
  433.   #
  434.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  435.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  436.   # from a version (or install over a version removed-but-not-purged) prior
  437.   # to the one in which the conffile was obsoleted.
  438.   # You should have  used replace_conffile_with_symlink_prepare() in the
  439.   # preinst.
  440.  
  441.   local conffile
  442.  
  443.   # validate arguments
  444.   if [ $# -ne 2 ]; then
  445.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  446.                 "number of arguments; expected 2, got $#"
  447.     exit $SHELL_LIB_USAGE_ERROR
  448.   fi
  449.  
  450.   oldconffile="$1"
  451.   newconffile="$2"
  452.  
  453.   remove_conffile_rollback "$_oldconffile"
  454.   if [ -f "$newconffile" ]; then
  455.     rm "$newconffile"
  456.   fi
  457. }
  458.  
  459. run () {
  460.   # syntax: run command [ argument ... ]
  461.   #
  462.   # Run specified command with optional arguments and report its exit status.
  463.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  464.   # or commands whose failure is not fatal to us.
  465.   #
  466.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  467.   # those cases the return value of the debconf command *must* be checked
  468.   # before the string returned by debconf is used for anything.
  469.  
  470.   local retval
  471.  
  472.   # validate arguments
  473.   if [ $# -lt 1 ]; then
  474.     usage_error "run() called with wrong number of arguments; expected at" \
  475.                 "least 1, got $#"
  476.     exit $SHELL_LIB_USAGE_ERROR
  477.   fi
  478.  
  479.   "$@" || retval=$?
  480.  
  481.   if [ ${retval:-0} -ne 0 ]; then
  482.     observe "command \"$*\" exited with status $retval"
  483.   fi
  484. }
  485.  
  486. make_symlink_sane () {
  487.   # syntax: make_symlink_sane symlink target
  488.   #
  489.   # Ensure that the symbolic link symlink exists, and points to target.
  490.   #
  491.   # If symlink does not exist, create it and point it at target.
  492.   #
  493.   # If symlink exists but is not a symbolic link, back it up.
  494.   #
  495.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  496.   # it.
  497.   #
  498.   # If symlink exists, is a symbolic link, and already points to target, do
  499.   # nothing.
  500.   #
  501.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  502.  
  503.   # Validate arguments.
  504.   if [ $# -ne 2 ]; then
  505.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  506.       "expected 2, got $#"
  507.     exit $SHELL_LIB_USAGE_ERROR
  508.   fi
  509.  
  510.   # We could just use the positional parameters as-is, but that makes things
  511.   # harder to follow.
  512.   local symlink target
  513.  
  514.   symlink="$1"
  515.   target="$2"
  516.  
  517.   if [ -L "$symlink" ] && [ "$(readlink "$symlink")" = "$target" ]; then
  518.       observe "link from $symlink to $target already exists"
  519.   else
  520.     observe "creating symbolic link from $symlink to $target"
  521.     mkdir -p "${target%/*}" "${symlink%/*}"
  522.     ln -s -b -S ".dpkg-old" "$target" "$symlink"
  523.   fi
  524. }
  525.  
  526. migrate_dir_to_symlink () {
  527.   # syntax: migrate_dir_to_symlink old_location new_location
  528.   #
  529.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  530.   # symbolic link to a directory or vice versa; instead, the existing state
  531.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  532.   # there is one."
  533.   #
  534.   # We have to do it ourselves.
  535.   #
  536.   # This function moves the contents of old_location, a directory, into
  537.   # new_location, a directory, then makes old_location a symbolic link to
  538.   # new_location.
  539.   #
  540.   # old_location need not exist, but if it does, it must be a directory (or a
  541.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  542.   # exists already and is not a directory, it is backed up.
  543.   #
  544.   # This function should be called from a package's preinst so that other
  545.   # packages unpacked after this one --- but before this package's postinst runs
  546.   # --- are unpacked into new_location even if their payloads contain
  547.   # old_location filespecs.
  548.  
  549.   # Validate arguments.
  550.   if [ $# -ne 2 ]; then
  551.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  552.                 "arguments; expected 2, got $#"
  553.     exit $SHELL_LIB_USAGE_ERROR
  554.   fi
  555.  
  556.   # We could just use the positional parameters as-is, but that makes things
  557.   # harder to follow.
  558.   local new old
  559.  
  560.   old="$1"
  561.   new="$2"
  562.  
  563.   # Is old location a symlink?
  564.   if [ -L "$old" ]; then
  565.     # Does it already point to new location?
  566.     if [ "$(readlink "$old")" = "$new" ]; then
  567.       # Nothing to do; migration has already been done.
  568.       observe "migration of $old to $new already done"
  569.       return 0
  570.     else
  571.       # Back it up.
  572.       warn "backing up symbolic link $old as $old.dpkg-old"
  573.       mv -b "$old" "$old.dpkg-old"
  574.     fi
  575.   fi
  576.  
  577.   # Does old location exist, but is not a directory?
  578.   if [ -e "$old" ] && ! [ -d "$old" ]; then
  579.       # Back it up.
  580.       warn "backing up non-directory $old as $old.dpkg-old"
  581.       mv -b "$old" "$old.dpkg-old"
  582.   fi
  583.  
  584.   observe "migrating $old to $new"
  585.  
  586.   # Is new location a symlink?
  587.   if [ -L "$new" ]; then
  588.     # Does it point the wrong way, i.e., back to where we're migrating from?
  589.     if [ "$(readlink "$new")" = "$old" ]; then
  590.       # Get rid of it.
  591.       observe "removing symbolic link $new which points to $old"
  592.       rm "$new"
  593.     else
  594.       # Back it up.
  595.       warn "backing up symbolic link $new as $new.dpkg-old"
  596.       mv -b "$new" "$new.dpkg-old"
  597.     fi
  598.   fi
  599.  
  600.   # Does new location exist, but is not a directory?
  601.   if [ -e "$new" ] && ! [ -d "$new" ]; then
  602.     warn "backing up non-directory $new as $new.dpkg-old"
  603.     mv -b "$new" "$new.dpkg-old"
  604.   fi
  605.  
  606.   # Create new directory if it does not yet exist.
  607.   if ! [ -e "$new" ]; then
  608.     observe "creating $new"
  609.     mkdir -p "$new"
  610.   fi
  611.  
  612.   # Copy files in old location to new location.  Back up any filenames that
  613.   # already exist in the new location with the extension ".dpkg-old".
  614.   observe "copying files from $old to $new"
  615.   if ! (cd "$old" && cp -a -b -S ".dpkg-old" . "$new"); then
  616.     die "error(s) encountered while copying files from $old to $new"
  617.   fi
  618.  
  619.   # Remove files at old location.
  620.   observe "removing $old"
  621.   rm -r "$old"
  622.  
  623.   # Create symlink from old location to new location.
  624.   make_symlink_sane "$old" "$new"
  625. }
  626.  
  627. # vim:set ai et sw=2 ts=2 tw=80:
  628.  
  629. # GOBSTOPPER: The X Strike Force shell library ends here.
  630.  
  631. EXCLUDE_DIR=/var/lib/xfonts
  632. EXCLUDE=$EXCLUDE_DIR/excluded-aliases
  633.  
  634. if [ "$1" = "configure" ]; then
  635.     if ! [ -f $EXCLUDE ]; then
  636.         [ -d $EXCLUDE_DIR ] || mkdir -m 755 -p $EXCLUDE_DIR
  637.         echo '!! Excluded alias files to be ignored by update-fonts-alias(8)' > $EXCLUDE
  638.     fi
  639. fi
  640.  
  641.  
  642.  
  643. # vim:set ai et sw=4 ts=4 tw=80:
  644.